package com.exam.controller;

import com.exam.entity.Exam;
import com.exam.service.ExamService;
import com.exam.service.NoticeService;
import com.exam.service.QuestionBankService;
import com.exam.vo.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author 小聋包
 * @Date 2024/4/16 19:13
 * @Version 1.0
 */
@RestController
@RequiredArgsConstructor
@Api(tags="三个角色公共的相关接口")
@RequestMapping("/public")
public class PublicController {
    private final ExamService examService;

    private final QuestionBankService questionBankService;

    private final NoticeService noticeService;
    @ApiOperation("根据信息查询考试信息")
    @PostMapping("/getExamInfo")
    @ApiImplicitParams({
            @ApiImplicitParam(name="examQueryVo",value ="考试信息查询vo对象",required = true,dataType ="examQueryVo",paramType = "body")
    })
    public CommonResult<PageResponse<Exam>>getExamInfo(@RequestBody ExamQueryVo examQueryVo){
        return CommonResult.<PageResponse<Exam>>builder()
                .data(examService.getExamPage(examQueryVo))
                .build();
    }
    @ApiOperation("根据考试id查询考试的信息和题目要求")
    @GetMapping("/getExamInfoById")
    @ApiImplicitParams({@ApiImplicitParam(name = "examId",value = "考试Id",required = true,dataType = "int",paramType = "query")})
    public CommonResult<AddExamByQuestionVo> getExamInfoById(@RequestParam Integer examId){
        return CommonResult.<AddExamByQuestionVo>builder()
                .data(examService.getExamInfoById(examId))
                .build();
    }
    @ApiOperation("查询考试的所有信息")
    @GetMapping("/allExamInfo")
    public CommonResult<List<Exam>> allExamInfo(){

        return CommonResult.<List<Exam>>builder()
                .data(examService.list(null))
                .build();
    }

    @ApiOperation("获取题库中所有题目类型的数量")
    @GetMapping("/getBankHaveQuestionSumByType")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "bankName",value = "题库名称",dataType = "string",paramType = "query"),
            @ApiImplicitParam(name="pageNo",value = "页面数",required = true,dataType = "int",paramType = "query"),
            @ApiImplicitParam(name = "pageSize",value = "页面大小",required = true,dataType = "int",paramType = "query")
    })
    public CommonResult<PageResponse<BankHaveQuestionSum>>getBankHaveQuestionSumType(@RequestParam(required = false) String bankName,
                                                                                     Integer pageNo,Integer pageSize){
        return CommonResult.<PageResponse<BankHaveQuestionSum>>builder()
                .data(questionBankService.getBankHaveQuestionSumByType(bankName,pageNo,pageSize))
                .build();
    }

    @ApiOperation("根据题库获取所有的题目信息(单选，多选，判断题")
    @GetMapping("/getQuestionBank")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "bankId",value = "题库Id",required = true,dataType = "int",paramType = "query")
    })
    public CommonResult<List<QuestionVo>>getQuestionBank(Integer bankId){
        return CommonResult.<List<QuestionVo>>builder()
                .data(questionBankService.getQuestionByBankId(bankId))
                .build();
    }

    @ApiOperation("根据题库id和题目类型获取题目信息 type(1单选  2多选 3判断)")
    @GetMapping("/getQuestionByBankIdAndType")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "bankId",value = "题库id",required = true,dataType = "int",paramType = "query"),
            @ApiImplicitParam(name = "type",value = "题目类型",required = true,dataType = "int",paramType = "query")
    })
    public CommonResult<List<QuestionVo>>getQuestionByBankIdAndType(Integer bankId,Integer type){
        return CommonResult.<List<QuestionVo>>builder()
                .data(questionBankService.getQuestionByBankIdAndType(bankId,type))
                .build();
    }

    @ApiOperation("获取当前系统最新的公告")
    @GetMapping("/getCurrentNewNotice")
    public  CommonResult<String> getCurrentNewNotice(){
        return CommonResult.<String>builder()
                .data(noticeService.getCurrentNotice())
                .build();
    }
}
